// 身份证号识别性别出生日期
export default {
	/* 时间戳转化为年月日 */
	formatDate(cellValue) {
	  if (cellValue == null || cellValue == "") return "";
	  var date = new Date(cellValue) 
	  var year = date.getFullYear()
	  var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
	  var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() 
	  var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours() 
	  var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() 
	  var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
	  return year + '-' + month + '-' + day 
	},
	inputChange(cardNo) {
		const reg =
			/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
		if (reg.test(cardNo)) {
			var org_birthday = cardNo.substring(6, 14);
			var org_gender = cardNo.substring(16, 17);
			var sex = org_gender % 2 == 1 ? "男" : "女";
			var birthday =
				org_birthday.substring(0, 4) +
				"-" +
				org_birthday.substring(4, 6) +
				"-" +
				org_birthday.substring(6, 8);
			var birthdays = new Date(birthday.replace(/-/g, "-"));
			const userInfo = {
				sex: sex,
				birthday: birthday
			};

			return userInfo
		} else {
			return false;
		}
	},
	//获取url中参数的方法
	GetQueryString(name) {
		var url = window.location.href;
		try {
			var cs = url.split('?')[1]; //获取?之后的参数字符串
			var cs_arr = cs.split('&'); //参数字符串分割为数组
			for (var i = 0; i < cs_arr.length; i++) { //遍历数组，拿到json对象
				if (cs_arr[i].split('=')[0] == name) {
					return cs_arr[i].split('=')[1];
				}
			}
			return null;
		} catch {
			return null;
		}
	},
	/* JavaScript 中检查一个字符串是否以 "blob:" 开头 */
	isBlobURL(url) { 
		console.log(url.startsWith('blob:'),"url.startsWith('blob:')");
	  return url.startsWith('blob:');  
	},
	convertImageToBob(imgUrl){
		debugger
		var xhr = new XMLHttpRequest();
		xhr.open("GET", imgUrl, true);
		xhr.responseType = "blob";
		xhr.send();
		xhr.onload = function() {
			console.log(this.status,this,"=====");
		  if (this.status === 200) {
		    var blob = this.response;
		    var img = document.createElement("img");
		    img.onload = function(e) {
		      window.URL.revokeObjectURL(img.src); // 清除释放
		    };
		    img.src = window.URL.createObjectURL(blob);
		    document.body.appendChild(img); // 将图片添加到页面中
		  }
		};
		
	}
	

	
	
}